package com.ymatou.operate.trading.api.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.ActivityVo;
import com.ymatou.iapi.trading.operate.parameter.OrderGroupVo;
import com.ymatou.iapi.trading.operate.parameter.OrderItemVo;
import com.ymatou.iapi.trading.operate.parameter.OrderVo;
import com.ymatou.iapi.trading.operate.parameter.SellerCouponVo;
import com.ymatou.iapi.trading.operate.parameter.YmatouCouponVo;
import com.ymatou.iapi.trading.operate.parameter.enums.ActivityPromotionTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.AppTerminalSourceEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.OrderSourceEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.OrderTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.PriceTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.ProductRefundChannelEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.SalesTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.SellerCouponApplianceTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.TerminalSourceEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.YmatouCouponApplianceTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.req.ApplySalesRefundRequestBean;
import com.ymatou.iapi.trading.operate.parameter.req.PlaceOrderReq;
import com.ymatou.iapi.trading.operate.service.PlaceOrderCall;
import com.ymatou.operate.trading.api.parameter.SalesRefundSuccessRequestBean;
import com.ymatou.operate.trading.api.service.SalesRefundSuccessRequestCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AccountCallService;
import com.ymttest.business.service.CouponCallService;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.business.service.ProductCallService;
import com.ymttest.database.model.YmtRefundBill;
import com.ymttest.database.model.YmtRefundProduct;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.database.sqlwapper.YmtRefundWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

/**
 * 退货/退款成功完成接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_SalesRefundSuccessRequest {
    private static SalesRefundSuccessRequestBean salesrefundsuccessrequestBean;
    private static SalesRefundSuccessRequestCall salesrefundsuccessrequestCall;

    @BeforeClass
    public static void setUp() {
        Logger.createResultFile("退货/退款成功完成接口");
    }

    @Before
    public void caseUp() {
        salesrefundsuccessrequestBean = new SalesRefundSuccessRequestBean();
        salesrefundsuccessrequestCall = new SalesRefundSuccessRequestCall();
    }

    @AfterClass
    public static void tearDown() {
        Logger.generateResult(salesrefundsuccessrequestCall.getOpurl());
    }

    @After
    public void caseDown() {
        Logger.end();
    }

    // 一个订单下面多个商品
    private Map placeOrder() {
        Map map = new HashMap();
        try {
            PlaceOrderReq placeorderBean = new PlaceOrderReq();
            PlaceOrderCall placeorderCall = new PlaceOrderCall();
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
            // 创建产品
            Logger.comment("前置数据准备");
            HashMap<String, Object> productInfo = ProductCallService
                    .createProduct(sellerId, 3);
            Logger.comment("前置数据准备结束");
            String productId = (String) productInfo.get("productId");
            Logger.debug("productId:" + productId);
            String productName = (String) productInfo.get("productName");
            String pic = (String) productInfo.get("pic");
            BigDecimal price = (BigDecimal) (productInfo.get("price"));
            String catalogId = (String) productInfo.get("catalogId");
            YmatouCouponVo ymtCoupon = new YmatouCouponVo();
            // 平台优惠券
            BigDecimal couponValue = new BigDecimal(13);
            String couponCode = new OrderCallService().receivePlatformCoupon(userId, couponValue);
            ymtCoupon.setApplianceType(YmatouCouponApplianceTypeEnum.ALL);
            ymtCoupon.setCouponCode(couponCode);
            ymtCoupon.setCouponValue(couponValue);
            placeorderBean.setAppId("AutoTest");
            placeorderBean.setYmatouCoupon(ymtCoupon);
            placeorderBean.setUserId(userId);
            placeorderBean.setRequestId(TestDataManager.getRandomUUID()
                    .toString());
            placeorderBean.setTerminalSource(TerminalSourceEnum.IOS);
            placeorderBean.setAppTerminalSource(AppTerminalSourceEnum.Phone);
            placeorderBean.setSourceIp("127.0.0.1");
            placeorderBean.setAppId("ios");
            placeorderBean.setDeviceId("7777777777888888888888999");
            OrderGroupVo groupVo1 = new OrderGroupVo();
            placeorderBean.setOrderSource(OrderSourceEnum.PC);
            // 商家优惠券
            BigDecimal sellerCouponValue = new BigDecimal(15);
            String sellerCouponCode = new CouponCallService().receiveCouponInfo(sellerId, userId,
                    couponValue);
            SellerCouponVo sellerCoupon = new SellerCouponVo();
            sellerCoupon.setApplianceType(SellerCouponApplianceTypeEnum.ALL);
            sellerCoupon.setCouponCode(sellerCouponCode);
            sellerCoupon.setCouponValue(sellerCouponValue);
            groupVo1.setSellerCoupon(sellerCoupon);
            groupVo1.setSellerId(sellerId);
            List<OrderVo> orders = new ArrayList<OrderVo>();
            OrderVo ordervo1 = new OrderVo();
            ordervo1.setAutoCancelOrderHours(new BigDecimal(1));
            ordervo1.setOrderType(OrderTypeEnum.Spot);
            ordervo1.setPaidFull(true);
            ordervo1.setAddress("上海市闸北区灵石路636号");
            ordervo1.setLeaveWord("ymt autotest");
            ordervo1.setPhone("13100000001");
            ordervo1.setPostCode("200001");
            ordervo1.setTelephone("021-51002100");
            ordervo1.setReceiveName("李四");
            List<OrderItemVo> items = new ArrayList<OrderItemVo>();
            OrderItemVo orderitem1 = new OrderItemVo();
            orderitem1.setCatalogId(TestDataManager.getRandomUUID().toString());
            orderitem1.setProductNum(3);
            orderitem1.setProductName(productName);
            orderitem1.setPriceType(PriceTypeEnum.VipPrice);
            orderitem1.setProductId(TestDataManager.getRandomUUID().toString());
            price = new BigDecimal(210);
            orderitem1.setEarnestPrice(price);
            orderitem1.setProductPrice(price);
            orderitem1.setOriginalPrice(price);
            orderitem1.setSalesType(SalesTypeEnum.AlreadyInStock);
            orderitem1.setLogisticsType(LogisticsTypeEnum.SailProtect);
            orderitem1.setProductRefundChannel(ProductRefundChannelEnum.Official);
            orderitem1.setBrandId(5);
            orderitem1.setPackageNo("11111111");
            orderitem1
                    .setProductDetailInfo("e5a1eccf-6a14-458f-b907-35dc9a3d2713#适用人群:b13e9eb1-98d6-4d39-8c35-225758e443d3#男");
            orderitem1.setProductRecordNo("1234567");
            orderitem1.setProductRefundChannel(ProductRefundChannelEnum.Official);
            orderitem1
                    .setProperty("06f25e0c-e431-44ae-8a07-4d0bc824e3bd#尺寸:951a814e-2ded-4241-b9a0-91b2cd9a44fd#6,d2f663ea-3214-4344-abce-a8eaffcc43ce#颜色:f3ed3ad7-a084-450b-b698-256542963306#红色");
            ActivityVo activity = new ActivityVo();
            activity.setActivityId(46870);
            activity.setActivityBeginDate(YMTDateUtil.getBeforeOrNextDay(-10, "yyyy-MM-dd'T'HH:mm:ss"));
            activity.setActivityEndDate(YMTDateUtil.getBeforeOrNextDay(10, "yyyy-MM-dd'T'HH:mm:ss"));
            activity.setActivityTemplateId(12345678);
            activity.setCommissionRate(new BigDecimal(1.1));
            activity.setCost(true);
            activity.setFeeFree(false);
            activity.setPremium(new BigDecimal(1.5));
            activity.setPromotionPrice(new BigDecimal(15));
            activity.setPromotionType(ActivityPromotionTypeEnum.DiscountRate);
            activity.setUseCoupon(true);
            orderitem1.setActivity(activity);
            ordervo1.setOrderItems(items);
            ordervo1.setFreight(new BigDecimal("21"));
            // 第2件商品
            OrderItemVo orderitem2 = new OrderItemVo();
            orderitem2.setCatalogId(TestDataManager.getRandomUUID().toString());
            orderitem2.setProductNum(1);
            orderitem2.setProductName(productName);
            orderitem2.setPriceType(PriceTypeEnum.VipPrice);
            orderitem2.setProductId(TestDataManager.getRandomUUID().toString());
            price = new BigDecimal(270);
            orderitem2.setEarnestPrice(price);
            orderitem2.setProductPrice(price);
            orderitem2.setOriginalPrice(price);
            orderitem2.setSalesType(SalesTypeEnum.AlreadyInStock);
            orderitem2.setLogisticsType(LogisticsTypeEnum.SailProtect);
            orderitem2.setProductRefundChannel(ProductRefundChannelEnum.Official);
            orderitem2.setBrandId(5);
            orderitem2.setPackageNo("11111111");
            orderitem2
                    .setProductDetailInfo("e5a1eccf-6a14-458f-b907-35dc9a3d2713#适用人群:b13e9eb1-98d6-4d39-8c35-225758e443d3#男");
            orderitem2.setProductRecordNo("1234567");
            orderitem2.setProductRefundChannel(ProductRefundChannelEnum.Official);
            orderitem2
                    .setProperty("06f25e0c-e431-44ae-8a07-4d0bc824e3bd#尺寸:951a814e-2ded-4241-b9a0-91b2cd9a44fd#6,d2f663ea-3214-4344-abce-a8eaffcc43ce#颜色:f3ed3ad7-a084-450b-b698-256542963306#红色");
            orderitem2.setActivity(activity);
            items.add(orderitem1);
            items.add(orderitem2);
            ordervo1.setOrderItems(items);
            ordervo1.setFreight(new BigDecimal("21"));
            orders.add(ordervo1);
            groupVo1.setOrders(orders);
            placeorderBean.setOrderGroups(Arrays.asList(groupVo1));
            placeorderCall.setData(false, placeorderBean);
            placeorderCall.callService();
            JSONArray orderIds = placeorderCall.getOrderIds();
            int tradingId = placeorderCall.getTradingId();
            map.put("orderIds", orderIds);
            map.put("tradingId", tradingId);
        } catch (Exception e) {
            Logger.fail(e);
        }
        return map;
    }

    @Test
    @Category({P1.class})
    @TestCase
    public void Tc_SalesRefundSuccessRequest_001() {
        Logger.start(true, "确认收货前,订单多个商品依次全部全款退款");
        try {
            Map map = placeOrder();
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
            JSONArray orderIds = (JSONArray) map.get("orderIds");
            int tradingId = (Integer) map.get("tradingId");
            int orderId = orderIds.getInt(0);
            OrderCallService orderCallService = new OrderCallService();
            // 付款金额
            BigDecimal amount = orderCallService.getNeedPrePayAmountOfCash(orderId);
            // 付款
            orderCallService.orderPayRequest(userId, amount, tradingId);
            // 卖家接单
            orderCallService.acceptOrder(orderId, sellerId);
            // 申请退款
            ApplySalesRefundRequestBean applysalesrefundrequestBean=orderCallService.applySalesRefundRequestInJavaBean(orderId);
            String refundNo1=applysalesrefundrequestBean.getSalesRefundInfoList().get(0).getRefundBillNo();
            String refundNo2=applysalesrefundrequestBean.getSalesRefundInfoList().get(0).getRefundBillNo();
            salesrefundsuccessrequestBean.setOperatorInfo("autotest");
            salesrefundsuccessrequestBean.setOrderId(orderId);
            salesrefundsuccessrequestBean.setRefundBillNo(refundNo1);
            salesrefundsuccessrequestCall.setData(salesrefundsuccessrequestBean);
            Logger.comment("退该订单号" + orderId + "第一件商品");
            salesrefundsuccessrequestCall.callService();
            Logger.verifyEquals("ok", salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
            salesrefundsuccessrequestBean.setOrderId(orderId);
            salesrefundsuccessrequestBean.setRefundBillNo(refundNo2);
            salesrefundsuccessrequestCall.setData(salesrefundsuccessrequestBean);
            Logger.comment("退该订单号" + orderId + "第二件商品");
            salesrefundsuccessrequestCall.callService();
            DefaultWapper defaultWapper = new DefaultWapper();
            if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {
                // 数据库验
                // 查询交易退款结算表
                List<Map> settlementInvoiceList = defaultWapper.selectYmtSettlementInvoice(orderId);
                // 订单商品表
                List<Map> orderInfoList = defaultWapper.selectOrderInfoByOderId(orderId);
                // 订单主表
                List<Map> ymtOrders = defaultWapper.selectOrderByOderId(orderId);
                // ymtOrderState 表
                List<Map> ymtOrderState = defaultWapper.selectOrderStateByOderId(orderId);
                YmtRefundWapper ymtRefund = new YmtRefundWapper();
                Map m = new HashMap();
                m.put("orderId", orderId);
                // m.put("refundBillNo", refundBillNo);
                for (int i = 0; i < orderInfoList.size(); i++) {
                    // 订单退货记录
                    YmtRefundBill refundBill = ymtRefund.selectRefundBill(m).get(i);
                    // 退货的商品记录
                    YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(m).get(i);
                    // 退款退货商品 catalogid
                    String catalogId = refundPro.getCatalogId();
                    // 商品使用的平台优惠券
                    BigDecimal productYmtCoupon = BigDecimal.ZERO;
                    for (Map m1 : orderInfoList) {
                        if (((String) m1.get("sCatalogId")).equals(catalogId)) {
                            productYmtCoupon = (BigDecimal) m1.get("fYmtCouponAmount");
                        }
                    }
                    Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
                    Logger.comment("校验Ymt_RefundBill表");
                    Logger.verifyEquals(orderId, refundBill.getOrderId(), "验证OrderId");
                    Logger.verifyEquals("YMTTK" + i + orderId, refundBill.getRefundBillNo(), "验证RefundBillNo");
                    Logger.verifyEquals(1, refundBill.getRefundStatus(), "验证RefundStatus");
                    Logger.verifyEquals(1, refundBill.getSettlementStatus(), "验证SettlementStatus");
                    Logger.verifyEquals(10, refundBill.getSalesRefundStatus(), "验证SalesRefundStatus");
                    Logger.verifyEquals(1, refundBill.getRefundType(), "验证RefundType");
                    Logger.verifyEquals("autotest refund", refundBill.getReason(), "验证Reason");
                    // 退的平台优惠券
                    Logger.verifyEquals(productYmtCoupon,
                            refundBill.getSettlementAmountOfCoupon(),
                            "验证SettlementAmountOfCoupon");
                    Logger.verifyEquals(sellerId, refundBill.getSellerId(), "验证SellerId");
                    Logger.verifyEquals(userId, refundBill.getBuyerId(), "验证BuyerId");
                    Logger.verifyEquals(orderId, refundBill.getOrderId(), "验证OrderId");
                    Logger.comment("校验Ymt_RefundProduct表");
                    Logger.verifyEquals(orderId, refundPro.getOrderId(), "验证OrderId");
                    Logger.verifyEquals("YMTTK" + i + orderId, refundPro.getRefundBillNo(), "验证RefundBillNo");
                    Logger.comment("校验Ymt_SettlementInvoice表");
                    Logger.verifyEquals("YMTTK" + i + orderId, (String) settlementInvoiceList.get(i).get("BusinessNo"),
                            "验证BusinessNo");
                    Logger.verifyEquals(2, (Integer) settlementInvoiceList.get(i)
                            .get("BusinessType"),
                            "验证BusinessType");
                    Logger.verifyEquals(orderId, (Integer) settlementInvoiceList.get(i)
                            .get("OrderId"),
                            "验证OrderId");
                    Logger.verifyEquals(((BigDecimal) settlementInvoiceList.get(i)
                            .get("CashAmount")).add((BigDecimal) settlementInvoiceList.get(i)
                            .get("CouponAmount")), (BigDecimal) settlementInvoiceList.get(i)
                            .get("TotalAmount"),
                            "验证TotalAmount");
                    Logger.verifyEquals(refundBill.getRefundAmount(), (BigDecimal) settlementInvoiceList.get(i)
                            .get("CashAmount"),
                            "验证CashAmount");
                    // 退的ymt 平台优惠券
                    Logger.verifyEquals(productYmtCoupon, (BigDecimal) settlementInvoiceList.get(i)
                            .get("CouponAmount"),
                            "验证CouponAmount");
                    Logger.verifyEquals(sellerId, (Integer) settlementInvoiceList.get(i)
                            .get("SellerId"),
                            "验证SellerId");
                    Logger.verifyEquals("退款结算", (String) settlementInvoiceList.get(i)
                            .get("Remark"),
                            "验证Remark");
                    Logger.verifyEquals(1, (Integer) settlementInvoiceList.get(i)
                            .get("SettlementStatus"),
                            "验证SettlementStatus");
                    Logger.verifyEquals(1, (Integer) settlementInvoiceList.get(i)
                            .get("SettlementUser"),
                            "验证SettlementUser");
                    Logger.verifyEquals("余额退款", (String) settlementInvoiceList.get(i)
                            .get("ProcessResult"),
                            "验证ProcessResult");
                    Logger.comment("校验ymt_orderinfo表");
                    Logger.verifyEquals(10, (Integer) orderInfoList.get(i)
                            .get("iProductRefundStatus"),
                            "验证iProductRefundStatus");
                }
                Logger.comment("校验ymt_orders表");
                Logger.verifyEquals(12, (Integer) ymtOrders.get(0).get("iTradingStatus"), "验证iTradingStatus");
                Logger.verifyEquals(10, (Integer) ymtOrders.get(0)
                        .get("iSalesRefundStatus"),
                        "验证iSalesRefundStatus");
                Logger.comment("校验ymt_orderstate表");
                Logger.verifyEquals((BigDecimal) ymtOrderState.get(0)
                        .get("fPaidAmountOfCash"), (BigDecimal) ymtOrderState.get(0)
                        .get("fRefundedAmountOfCash"),
                        "验证fRefundedAmountOfCash");
            }
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category({P1.class})
    @TestCase
    public void Tc_SalesRefundSuccessRequest_002() {
        Logger.start(true, "订单部分退款,然后确认收货");
        try {
            Map map = placeOrder();
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
            JSONArray orderIds = (JSONArray) map.get("orderIds");
            int tradingId = (Integer) map.get("tradingId");
            int orderId = orderIds.getInt(0);
            OrderCallService orderCallService = new OrderCallService();
            // 付款金额
            BigDecimal amount = orderCallService.getNeedPrePayAmountOfCash(orderId);
            // 付款
            orderCallService.orderPayRequest(userId, amount, tradingId);
            // 卖家接单
            orderCallService.acceptOrder(orderId, sellerId);
            // 发货
            orderCallService.dispatched(orderId, sellerId);
            // 申请退款
            String refundBillNo=orderCallService.applySalesRefundRequestInJava(orderId).getSalesRefundInfoList().get(0).getRefundBillNo();
            salesrefundsuccessrequestBean.setOperatorInfo("autotest");
            salesrefundsuccessrequestBean.setOrderId(orderId);
            salesrefundsuccessrequestBean.setRefundBillNo(refundBillNo);
            salesrefundsuccessrequestCall.setData(salesrefundsuccessrequestBean);
            salesrefundsuccessrequestCall.callService();
            Logger.verifyEquals("ok", salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
            // 确认收货
            orderCallService.confirmReceive(userId, orderId);
            DefaultWapper defaultWapper = new DefaultWapper();
            // 数据库验
            // 查询交易退款结算表
            List<Map> settlementInvoiceList = defaultWapper.selectYmtSettlementInvoice(orderId);
            // 订单商品表
            List<Map> orderInfoList = defaultWapper.selectOrderInfoByOderId(orderId);
            // 订单主表
            List<Map> ymtOrders = defaultWapper.selectOrderByOderId(orderId);
            // ymtOrderState 表
            List<Map> ymtOrderState = defaultWapper.selectOrderStateByOderId(orderId);
            YmtRefundWapper ymtRefund = new YmtRefundWapper();
            Map m = new HashMap();
            m.put("orderId", orderId);
            m.put("refundBillNo", refundBillNo);
            // 订单退货记录
            YmtRefundBill refundBill = ymtRefund.selectRefundBill(m).get(0);
            // 退货的商品记录
            YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(m).get(0);
            // 退款退货商品 catalogid
            String catalogId = refundPro.getCatalogId();
            // 商品使用的平台优惠券
            BigDecimal productYmtCoupon = BigDecimal.ZERO;
            for (Map m1 : orderInfoList) {
                if (((String) m1.get("sCatalogId")).equals(catalogId)) {
                    productYmtCoupon = (BigDecimal) m1.get("fYmtCouponAmount");
                }
            }
            Logger.comment("校验订单号" + orderId + "第1件商品");
            Logger.comment("校验Ymt_RefundBill表");
            Logger.verifyEquals(orderId, refundBill.getOrderId(), "验证OrderId");
            Logger.verifyEquals(refundBillNo, refundBill.getRefundBillNo(), "验证RefundBillNo");
            Logger.verifyEquals(1, refundBill.getRefundStatus(), "验证RefundStatus");
            Logger.verifyEquals(1, refundBill.getSettlementStatus(), "验证SettlementStatus");
            Logger.verifyEquals(10, refundBill.getSalesRefundStatus(), "验证SalesRefundStatus");
            Logger.verifyEquals(1, refundBill.getRefundType(), "验证RefundType");
            Logger.verifyEquals("autotest refund", refundBill.getReason(), "验证Reason");
            // 退的平台优惠券
            Logger.verifyEquals(productYmtCoupon,
                    refundBill.getSettlementAmountOfCoupon(),
                    "验证SettlementAmountOfCoupon");
            Logger.verifyEquals(sellerId, refundBill.getSellerId(), "验证SellerId");
            Logger.verifyEquals(userId, refundBill.getBuyerId(), "验证BuyerId");
            Logger.verifyEquals(orderId, refundBill.getOrderId(), "验证OrderId");
            Logger.comment("校验Ymt_RefundProduct表");
            Logger.verifyEquals(orderId, refundPro.getOrderId(), "验证OrderId");
            Logger.verifyEquals(refundBillNo, refundPro.getRefundBillNo(), "验证RefundBillNo");

            Logger.comment("校验Ymt_SettlementInvoice表 退款结算");
            Logger.verifyEquals(refundBillNo, (String) settlementInvoiceList.get(0).get("BusinessNo"),
                    "验证BusinessNo");
            Logger.verifyEquals(2, (Integer) settlementInvoiceList.get(0).get("BusinessType"),
                    "验证BusinessType");
            Logger.verifyEquals(orderId, (Integer) settlementInvoiceList.get(0).get("OrderId"),
                    "验证OrderId");
            Logger.verifyEquals(((BigDecimal) settlementInvoiceList.get(0).get("CashAmount"))
                    .add((BigDecimal) settlementInvoiceList.get(0)
                            .get("CouponAmount")), (BigDecimal) settlementInvoiceList.get(0)
                    .get("TotalAmount"),
                    "验证TotalAmount");
            Logger.verifyEquals(refundBill.getRefundAmount(),
                    (BigDecimal) settlementInvoiceList.get(0).get("CashAmount"),
                    "验证CashAmount");
            // 退的ymt 平台优惠券
            Logger.verifyEquals(productYmtCoupon, (BigDecimal) settlementInvoiceList.get(0).get("CouponAmount"),
                    "验证CouponAmount");
            Logger.verifyEquals(sellerId, (Integer) settlementInvoiceList.get(0).get("SellerId"),
                    "验证SellerId");
            Logger.verifyEquals("退款结算", (String) settlementInvoiceList.get(0).get("Remark"), "验证Remark");
            Logger.verifyEquals(1, (Integer) settlementInvoiceList.get(0).get("SettlementStatus"),
                    "验证SettlementStatus");
            Logger.verifyEquals(1, (Integer) settlementInvoiceList.get(0).get("SettlementUser"), "验证SettlementUser");
            Logger.verifyEquals("余额退款", (String) settlementInvoiceList.get(0).get("ProcessResult"), "验证ProcessResult");

            Logger.comment("校验Ymt_SettlementInvoice表 确认收货结算");
            Logger.verifyEquals(String.valueOf(orderId), (String) settlementInvoiceList.get(1).get("BusinessNo"),
                    "验证BusinessNo");
            Logger.verifyEquals(1, (Integer) settlementInvoiceList.get(1).get("BusinessType"),
                    "验证BusinessType");
            Logger.verifyEquals(orderId, (Integer) settlementInvoiceList.get(1).get("OrderId"),
                    "验证OrderId");
            Logger.verifyEquals(((BigDecimal) settlementInvoiceList.get(1).get("CashAmount"))
                    .add((BigDecimal) settlementInvoiceList.get(1)
                            .get("CouponAmount")), (BigDecimal) settlementInvoiceList.get(1)
                    .get("TotalAmount"),
                    "验证TotalAmount");
            Logger.verifyEquals(((BigDecimal) ymtOrderState.get(0).get("fPaidAmountOfCash"))
                    .subtract((BigDecimal) ymtOrderState.get(0).get("fRefundedAmountOfCash")),
                    (BigDecimal) settlementInvoiceList.get(1).get("CashAmount"),
                    "验证CashAmount");
            // 确认收货的ymt 平台优惠券
            Logger.verifyEquals(((BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount")).subtract(productYmtCoupon),
                    (BigDecimal) settlementInvoiceList.get(1).get("CouponAmount"),
                    "验证CouponAmount");
            Logger.verifyEquals(sellerId, (Integer) settlementInvoiceList.get(1).get("SellerId"),
                    "验证SellerId");
            Logger.verifyEquals("确认收货订单结算", (String) settlementInvoiceList.get(1).get("Remark"), "验证Remark");
            Logger.verifyEquals(0, (Integer) settlementInvoiceList.get(1).get("SettlementStatus"),
                    "验证SettlementStatus");
            Logger.verifyEquals(2, (Integer) settlementInvoiceList.get(1).get("SettlementUser"), "验证SettlementUser");
            Logger.verifyEquals(null, (String) settlementInvoiceList.get(1).get("ProcessResult"), "验证ProcessResult");
            Logger.comment("校验ymt_orderinfo表");
            Logger.verifyEquals(10, (Integer) orderInfoList.get(0).get("iProductRefundStatus"),
                    "验证iProductRefundStatus");
            Logger.verifyEquals(1, (Integer) orderInfoList.get(1).get("iProductRefundStatus"),
                    "验证iProductRefundStatus");
            Logger.comment("校验ymt_orders表");
            Logger.verifyEquals(4, (Integer) ymtOrders.get(0).get("iTradingStatus"), "验证iTradingStatus");
            Logger.verifyEquals(1, (Integer) ymtOrders.get(0).get("iSalesRefundStatus"), "验证iSalesRefundStatus");
            Logger.comment("校验ymt_orderstate表");
            Logger.verifyEquals((BigDecimal) settlementInvoiceList.get(0).get("CashAmount"), (BigDecimal) ymtOrderState
                    .get(0).get("fRefundedAmountOfCash"), "验证fRefundedAmountOfCash");
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category({P1.class})
    @TestCase
    public void Tc_SalesRefundSuccessRequest_003() {
        Logger.start(true, "确认收货后,部分退款");
        try {
            Map map = placeOrder();
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
            JSONArray orderIds = (JSONArray) map.get("orderIds");
            int tradingId = (Integer) map.get("tradingId");
            int orderId = orderIds.getInt(0);
            OrderCallService orderCallService = new OrderCallService();
            // 付款金额
            BigDecimal amount = orderCallService.getNeedPrePayAmountOfCash(orderId);
            // 付款
            orderCallService.orderPayRequest(userId, amount, tradingId);
            // 卖家接单
            orderCallService.acceptOrder(orderId, sellerId);
            // 发货
            orderCallService.dispatched(orderId, sellerId);
            // 确认收货
            orderCallService.confirmReceive(userId, orderId);
            // 申请退款
            String refundBillNo = orderCallService.applySalesRefundRequestInJava(orderId).getSalesRefundInfoList().get(0).getRefundBillNo();
            salesrefundsuccessrequestBean.setOperatorInfo("autotest");
            salesrefundsuccessrequestBean.setOrderId(orderId);
            salesrefundsuccessrequestBean.setRefundBillNo("YMTTK0" + orderId);
            salesrefundsuccessrequestCall.setData(salesrefundsuccessrequestBean);
            salesrefundsuccessrequestCall.callService();
            Logger.verifyEquals("ok", salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
            DefaultWapper defaultWapper = new DefaultWapper();
            // 数据库验
            // 查询交易退款结算表
            List<Map> settlementInvoiceList = defaultWapper.selectYmtSettlementInvoice(orderId);
            // 订单商品表
            List<Map> orderInfoList = defaultWapper.selectOrderInfoByOderId(orderId);
            // 订单主表
            List<Map> ymtOrders = defaultWapper.selectOrderByOderId(orderId);
            // ymtOrderState 表
            List<Map> ymtOrderState = defaultWapper.selectOrderStateByOderId(orderId);
            YmtRefundWapper ymtRefund = new YmtRefundWapper();
            Map m = new HashMap();
            m.put("orderId", orderId);
            m.put("refundBillNo", refundBillNo);
            // 订单退货记录
            YmtRefundBill refundBill = ymtRefund.selectRefundBill(m).get(0);
            // 退货的商品记录
            YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(m).get(0);
            // 退款退货商品 catalogid
            String catalogId = refundPro.getCatalogId();
            // 商品使用的平台优惠券
            BigDecimal productYmtCoupon = BigDecimal.ZERO;
            for (Map m1 : orderInfoList) {
                if (((String) m1.get("sCatalogId")).equals(catalogId)) {
                    productYmtCoupon = (BigDecimal) m1.get("fYmtCouponAmount");
                }
            }
            Logger.comment("校验订单号" + orderId + "第1件商品");
            Logger.comment("校验Ymt_RefundBill表");
            Logger.verifyEquals(orderId, refundBill.getOrderId(), "验证OrderId");
            Logger.verifyEquals(refundBillNo, refundBill.getRefundBillNo(), "验证RefundBillNo");
            Logger.verifyEquals(1, refundBill.getRefundStatus(), "验证RefundStatus");
            Logger.verifyEquals(1, refundBill.getSettlementStatus(), "验证SettlementStatus");
            Logger.verifyEquals(10, refundBill.getSalesRefundStatus(), "验证SalesRefundStatus");
            Logger.verifyEquals(1, refundBill.getRefundType(), "验证RefundType");
            Logger.verifyEquals("autotest refund", refundBill.getReason(), "验证Reason");
            // 退的平台优惠券
            Logger.verifyEquals(productYmtCoupon,
                    refundBill.getSettlementAmountOfCoupon(),
                    "验证SettlementAmountOfCoupon");
            Logger.verifyEquals(sellerId, refundBill.getSellerId(), "验证SellerId");
            Logger.verifyEquals(userId, refundBill.getBuyerId(), "验证BuyerId");
            Logger.verifyEquals(orderId, refundBill.getOrderId(), "验证OrderId");
            Logger.comment("校验Ymt_RefundProduct表");
            Logger.verifyEquals(orderId, refundPro.getOrderId(), "验证OrderId");
            Logger.verifyEquals(refundBillNo, refundPro.getRefundBillNo(), "验证RefundBillNo");

            Logger.comment("校验Ymt_SettlementInvoice表 确认收货结算");
            Logger.verifyEquals(String.valueOf(orderId), (String) settlementInvoiceList.get(0).get("BusinessNo"),
                    "验证BusinessNo");
            Logger.verifyEquals(1, (Integer) settlementInvoiceList.get(0).get("BusinessType"),
                    "验证BusinessType");
            Logger.verifyEquals(orderId, (Integer) settlementInvoiceList.get(0).get("OrderId"),
                    "验证OrderId");
            Logger.verifyEquals(((BigDecimal) settlementInvoiceList.get(0).get("CashAmount"))
                    .add((BigDecimal) settlementInvoiceList.get(0)
                            .get("CouponAmount")), (BigDecimal) settlementInvoiceList.get(0)
                    .get("TotalAmount"),
                    "验证TotalAmount");
            Logger.verifyEquals((BigDecimal) ymtOrderState.get(0).get("fPaidAmountOfCash"),
                    (BigDecimal) settlementInvoiceList.get(0).get("CashAmount"),
                    "验证CashAmount");
            // 平台优惠券
            Logger.verifyEquals((BigDecimal) ymtOrderState.get(0).get("fPaidAmountOfYmtCoupon"),
                    (BigDecimal) settlementInvoiceList.get(0).get("CouponAmount"),
                    "验证CouponAmount");
            Logger.verifyEquals(sellerId, (Integer) settlementInvoiceList.get(0).get("SellerId"),
                    "验证SellerId");
            Logger.verifyEquals("确认收货订单结算", (String) settlementInvoiceList.get(0).get("Remark"), "验证Remark");
            Logger.verifyEquals(0, (Integer) settlementInvoiceList.get(0).get("SettlementStatus"),
                    "验证SettlementStatus");
            Logger.verifyEquals(2, (Integer) settlementInvoiceList.get(0).get("SettlementUser"), "验证SettlementUser");
            Logger.verifyEquals(null, (String) settlementInvoiceList.get(0).get("ProcessResult"), "验证ProcessResult");

            Logger.comment("校验Ymt_SettlementInvoice表 退款结算");
            Logger.verifyEquals(refundBillNo, (String) settlementInvoiceList.get(1).get("BusinessNo"),
                    "验证BusinessNo");
            Logger.verifyEquals(2, (Integer) settlementInvoiceList.get(1).get("BusinessType"),
                    "验证BusinessType");
            Logger.verifyEquals(orderId, (Integer) settlementInvoiceList.get(1).get("OrderId"),
                    "验证OrderId");
            Logger.verifyEquals(((BigDecimal) settlementInvoiceList.get(1).get("CashAmount"))
                    .add((BigDecimal) settlementInvoiceList.get(1)
                            .get("CouponAmount")), (BigDecimal) settlementInvoiceList.get(1)
                    .get("TotalAmount"),
                    "验证TotalAmount");
            Logger.verifyEquals(refundBill.getRefundAmount(),
                    (BigDecimal) settlementInvoiceList.get(1).get("CashAmount"),
                    "验证CashAmount");
            // 确认收货的ymt 平台优惠券
            Logger.verifyEquals(refundBill.getSettlementAmountOfCoupon(),
                    (BigDecimal) settlementInvoiceList.get(1).get("CouponAmount"),
                    "验证CouponAmount");
            Logger.verifyEquals(sellerId, (Integer) settlementInvoiceList.get(1).get("SellerId"),
                    "验证SellerId");
            Logger.verifyEquals("退款结算", (String) settlementInvoiceList.get(1).get("Remark"), "验证Remark");
            Logger.verifyEquals(1, (Integer) settlementInvoiceList.get(1).get("SettlementStatus"),
                    "验证SettlementStatus");
            Logger.verifyEquals(2, (Integer) settlementInvoiceList.get(1).get("SettlementUser"), "验证SettlementUser");
            Logger.verifyEquals("余额退款", (String) settlementInvoiceList.get(1).get("ProcessResult"), "验证ProcessResult");
            Logger.comment("校验ymt_orderinfo表");
            Logger.verifyEquals(10, (Integer) orderInfoList.get(0).get("iProductRefundStatus"),
                    "验证iProductRefundStatus");
            Logger.verifyEquals(1, (Integer) orderInfoList.get(1).get("iProductRefundStatus"),
                    "验证iProductRefundStatus");
            Logger.comment("校验ymt_orders表");
            Logger.verifyEquals(4, (Integer) ymtOrders.get(0).get("iTradingStatus"), "验证iTradingStatus");
            Logger.verifyEquals(1, (Integer) ymtOrders.get(0).get("iSalesRefundStatus"), "验证iSalesRefundStatus");
            Logger.comment("校验ymt_orderstate表");
            Logger.verifyEquals((BigDecimal) settlementInvoiceList.get(1).get("CashAmount"), (BigDecimal) ymtOrderState
                    .get(0).get("fRefundedAmountOfCash"), "验证fRefundedAmountOfCash");
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category({P1.class})
    @TestCase
    public void Tc_SalesRefundSuccessRequest_004() {
        Logger.start(true, "确认收货后,订单多个商品依次全部全款退款");
        try {
            Map map = placeOrder();
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
            JSONArray orderIds = (JSONArray) map.get("orderIds");
            int tradingId = (Integer) map.get("tradingId");
            int orderId = orderIds.getInt(0);
            OrderCallService orderCallService = new OrderCallService();
            // 付款金额
            BigDecimal amount = orderCallService.getNeedPrePayAmountOfCash(orderId);
            // 付款
            orderCallService.orderPayRequest(userId, amount, tradingId);
            // 卖家接单
            orderCallService.acceptOrder(orderId, sellerId);
            // 卖家发货
            orderCallService.dispatched(orderId, sellerId);
            // 用户确认收货
            orderCallService.confirmReceive(sellerId, orderId);
            // 申请退款
            orderCallService.applySalesRefundRequestInJava(orderId);
            salesrefundsuccessrequestBean.setOperatorInfo("autotest");
            salesrefundsuccessrequestBean.setOrderId(orderId);
            salesrefundsuccessrequestBean.setRefundBillNo("YMTTK0" + orderId);
            salesrefundsuccessrequestCall.setData(salesrefundsuccessrequestBean);
            Logger.comment("退该订单号" + orderId + "第一件商品");
            salesrefundsuccessrequestCall.callService();
            Logger.verifyEquals("ok", salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
            salesrefundsuccessrequestBean.setOrderId(orderId);
            salesrefundsuccessrequestBean.setRefundBillNo("YMTTK1" + orderId);
            salesrefundsuccessrequestCall.setData(salesrefundsuccessrequestBean);
            Logger.comment("退该订单号" + orderId + "第二件商品");
            salesrefundsuccessrequestCall.callService();
            DefaultWapper defaultWapper = new DefaultWapper();
            if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {
                // 数据库验
                // 查询交易退款结算表
                List<Map> settlementInvoiceList = defaultWapper.selectYmtSettlementInvoice(orderId);
                // 订单商品表
                List<Map> orderInfoList = defaultWapper.selectOrderInfoByOderId(orderId);
                // 订单主表
                List<Map> ymtOrders = defaultWapper.selectOrderByOderId(orderId);
                // ymtOrderState 表
                List<Map> ymtOrderState = defaultWapper.selectOrderStateByOderId(orderId);
                YmtRefundWapper ymtRefund = new YmtRefundWapper();
                Map m = new HashMap();
                m.put("orderId", orderId);
                // m.put("refundBillNo", refundBillNo);
                for (int i = 0; i < orderInfoList.size(); i++) {
                    // 订单退货记录
                    YmtRefundBill refundBill = ymtRefund.selectRefundBill(m).get(i);
                    // 退货的商品记录
                    YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(m).get(i);
                    // 退款退货商品 catalogid
                    String catalogId = refundPro.getCatalogId();
                    // 商品使用的平台优惠券
                    BigDecimal productYmtCoupon = BigDecimal.ZERO;
                    for (Map m1 : orderInfoList) {
                        if (((String) m1.get("sCatalogId")).equals(catalogId)) {
                            productYmtCoupon = (BigDecimal) m1.get("fYmtCouponAmount");
                        }
                    }
                    Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
                    Logger.comment("校验Ymt_RefundBill表");
                    Logger.verifyEquals(orderId, refundBill.getOrderId(), "验证OrderId");
                    Logger.verifyEquals("YMTTK" + i + orderId, refundBill.getRefundBillNo(), "验证RefundBillNo");
                    Logger.verifyEquals(1, refundBill.getRefundStatus(), "验证RefundStatus");
                    Logger.verifyEquals(1, refundBill.getSettlementStatus(), "验证SettlementStatus");
                    Logger.verifyEquals(10, refundBill.getSalesRefundStatus(), "验证SalesRefundStatus");
                    Logger.verifyEquals(1, refundBill.getRefundType(), "验证RefundType");
                    Logger.verifyEquals("autotest refund", refundBill.getReason(), "验证Reason");
                    // 退的平台优惠券
                    Logger.verifyEquals(productYmtCoupon,
                            refundBill.getSettlementAmountOfCoupon(),
                            "验证SettlementAmountOfCoupon");
                    Logger.verifyEquals(sellerId, refundBill.getSellerId(), "验证SellerId");
                    Logger.verifyEquals(userId, refundBill.getBuyerId(), "验证BuyerId");
                    Logger.verifyEquals(orderId, refundBill.getOrderId(), "验证OrderId");
                    Logger.comment("校验Ymt_RefundProduct表");
                    Logger.verifyEquals(orderId, refundPro.getOrderId(), "验证OrderId");
                    Logger.verifyEquals("YMTTK" + i + orderId, refundPro.getRefundBillNo(), "验证RefundBillNo");
                    Logger.comment("校验Ymt_SettlementInvoice表");
                    Logger.verifyEquals("YMTTK" + i + orderId,
                            (String) settlementInvoiceList.get(i + 1).get("BusinessNo"),
                            "验证BusinessNo");
                    Logger.verifyEquals(2, (Integer) settlementInvoiceList.get(i + 1)
                            .get("BusinessType"),
                            "验证BusinessType");
                    Logger.verifyEquals(orderId, (Integer) settlementInvoiceList.get(i + 1)
                            .get("OrderId"),
                            "验证OrderId");
                    Logger.verifyEquals(((BigDecimal) settlementInvoiceList.get(i + 1)
                            .get("CashAmount")).add((BigDecimal) settlementInvoiceList.get(i + 1)
                            .get("CouponAmount")), (BigDecimal) settlementInvoiceList.get(i + 1)
                            .get("TotalAmount"),
                            "验证TotalAmount");
                    Logger.verifyEquals(refundBill.getRefundAmount(), (BigDecimal) settlementInvoiceList.get(i + 1)
                            .get("CashAmount"),
                            "验证CashAmount");
                    // 退的ymt 平台优惠券
                    Logger.verifyEquals(productYmtCoupon, (BigDecimal) settlementInvoiceList.get(i + 1)
                            .get("CouponAmount"),
                            "验证CouponAmount");
                    Logger.verifyEquals(sellerId, (Integer) settlementInvoiceList.get(i + 1)
                            .get("SellerId"),
                            "验证SellerId");
                    Logger.verifyEquals("退款结算", (String) settlementInvoiceList.get(i + 1)
                            .get("Remark"),
                            "验证Remark");
                    Logger.verifyEquals(1, (Integer) settlementInvoiceList.get(i + 1)
                            .get("SettlementStatus"),
                            "验证SettlementStatus");
                    Logger.verifyEquals(2, (Integer) settlementInvoiceList.get(i + 1)
                            .get("SettlementUser"),
                            "验证SettlementUser");
                    Logger.verifyEquals("余额退款", (String) settlementInvoiceList.get(i + 1)
                            .get("ProcessResult"),
                            "验证ProcessResult");
                    Logger.comment("校验ymt_orderinfo表");
                    Logger.verifyEquals(10, (Integer) orderInfoList.get(i)
                            .get("iProductRefundStatus"),
                            "验证iProductRefundStatus");
                }
                Logger.comment("校验ymt_orders表");
                Logger.verifyEquals(10, (Integer) ymtOrders.get(0)
                        .get("iSalesRefundStatus"),
                        "验证iSalesRefundStatus");
                Logger.comment("校验ymt_orderstate表");
                Logger.verifyEquals((BigDecimal) ymtOrderState.get(0)
                        .get("fPaidAmountOfCash"), (BigDecimal) ymtOrderState.get(0)
                        .get("fRefundedAmountOfCash"),
                        "验证fRefundedAmountOfCash");
            }

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category({P1.class})
    @TestCase
    public void Tc_SalesRefundSuccessRequest_005() {
        Logger.start(true, "确认收货后,商家备用金不够,退货退款结算失败");
        try {
            Map map = placeOrder();
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
            JSONArray orderIds = (JSONArray) map.get("orderIds");
            int tradingId = (Integer) map.get("tradingId");
            int orderId = orderIds.getInt(0);
            OrderCallService orderCallService = new OrderCallService();
            // 付款金额
            BigDecimal amount = orderCallService.getNeedPrePayAmountOfCash(orderId);
            // 付款
            orderCallService.orderPayRequest(userId, amount, tradingId);
            // 卖家接单
            orderCallService.acceptOrder(orderId, sellerId);
            // 发货
            orderCallService.dispatched(orderId, sellerId);
            // 确认收货
            orderCallService.confirmReceive(userId, orderId);
            // 申请退款
            String refundBillNo=orderCallService.applySalesRefundRequestInJava(orderId).getSalesRefundInfoList().get(0).getRefundBillNo();
            // 重置商家余额
            AccountCallService accountCallService = new AccountCallService();
            String accountid = accountCallService.getAccountId(sellerId);
            accountCallService.resetAccount(accountid, new BigDecimal(10), new BigDecimal(0));

            salesrefundsuccessrequestBean.setOperatorInfo("autotest");
            salesrefundsuccessrequestBean.setOrderId(orderId);
            salesrefundsuccessrequestBean.setRefundBillNo("YMTTK0" + orderId);
            salesrefundsuccessrequestCall.setData(salesrefundsuccessrequestBean);
            salesrefundsuccessrequestCall.callService();
            Logger.verifyEquals("ok", salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
            DefaultWapper defaultWapper = new DefaultWapper();
            // 数据库验
            // 查询交易退款结算表
            List<Map> settlementInvoiceList = defaultWapper.selectYmtSettlementInvoice(orderId);
            // 订单商品表
            List<Map> orderInfoList = defaultWapper.selectOrderInfoByOderId(orderId);
            // 订单主表
            List<Map> ymtOrders = defaultWapper.selectOrderByOderId(orderId);
            // ymtOrderState 表
            List<Map> ymtOrderState = defaultWapper.selectOrderStateByOderId(orderId);
            YmtRefundWapper ymtRefund = new YmtRefundWapper();
            Map m = new HashMap();
            m.put("orderId", orderId);
            m.put("refundBillNo", refundBillNo);
            // 订单退货记录
            YmtRefundBill refundBill = ymtRefund.selectRefundBill(m).get(0);
            // 退货的商品记录
            YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(m).get(0);
            // 退款退货商品 catalogid
            String catalogId = refundPro.getCatalogId();
            // 商品使用的平台优惠券
            BigDecimal productYmtCoupon = BigDecimal.ZERO;
            for (Map m1 : orderInfoList) {
                if (((String) m1.get("sCatalogId")).equals(catalogId)) {
                    productYmtCoupon = (BigDecimal) m1.get("fYmtCouponAmount");
                }
            }
            Logger.comment("校验订单号" + orderId + "第1件商品");
            Logger.comment("校验Ymt_RefundBill表");
            Logger.verifyEquals(orderId, refundBill.getOrderId(), "验证OrderId");
            Logger.verifyEquals(refundBillNo, refundBill.getRefundBillNo(), "验证RefundBillNo");
            Logger.verifyEquals(0, refundBill.getRefundStatus(), "验证RefundStatus");
            Logger.verifyEquals(0, refundBill.getSettlementStatus(), "验证SettlementStatus");
            Logger.verifyEquals(10, refundBill.getSalesRefundStatus(), "验证SalesRefundStatus");
            Logger.verifyEquals(1, refundBill.getRefundType(), "验证RefundType");
            Logger.verifyEquals("autotest refund", refundBill.getReason(), "验证Reason");
            // 退的平台优惠券
            Logger.verifyEquals(productYmtCoupon,
                    refundBill.getSettlementAmountOfCoupon(),
                    "验证SettlementAmountOfCoupon");
            Logger.verifyEquals(sellerId, refundBill.getSellerId(), "验证SellerId");
            Logger.verifyEquals(userId, refundBill.getBuyerId(), "验证BuyerId");
            Logger.verifyEquals(orderId, refundBill.getOrderId(), "验证OrderId");
            Logger.comment("校验Ymt_RefundProduct表");
            Logger.verifyEquals(orderId, refundPro.getOrderId(), "验证OrderId");
            Logger.verifyEquals(refundBillNo, refundPro.getRefundBillNo(), "验证RefundBillNo");

            Logger.comment("校验Ymt_SettlementInvoice表 确认收货结算");
            Logger.verifyEquals(String.valueOf(orderId), (String) settlementInvoiceList.get(0).get("BusinessNo"),
                    "验证BusinessNo");
            Logger.verifyEquals(1, (Integer) settlementInvoiceList.get(0).get("BusinessType"),
                    "验证BusinessType");
            Logger.verifyEquals(orderId, (Integer) settlementInvoiceList.get(0).get("OrderId"),
                    "验证OrderId");
            Logger.verifyEquals(((BigDecimal) settlementInvoiceList.get(0).get("CashAmount"))
                    .add((BigDecimal) settlementInvoiceList.get(0)
                            .get("CouponAmount")), (BigDecimal) settlementInvoiceList.get(0)
                    .get("TotalAmount"),
                    "验证TotalAmount");
            Logger.verifyEquals((BigDecimal) ymtOrderState.get(0).get("fPaidAmountOfCash"),
                    (BigDecimal) settlementInvoiceList.get(0).get("CashAmount"),
                    "验证CashAmount");
            // 平台优惠券
            Logger.verifyEquals((BigDecimal) ymtOrderState.get(0).get("fPaidAmountOfYmtCoupon"),
                    (BigDecimal) settlementInvoiceList.get(0).get("CouponAmount"),
                    "验证CouponAmount");
            Logger.verifyEquals(sellerId, (Integer) settlementInvoiceList.get(0).get("SellerId"),
                    "验证SellerId");
            Logger.verifyEquals("确认收货订单结算", (String) settlementInvoiceList.get(0).get("Remark"), "验证Remark");
            Logger.verifyEquals(0, (Integer) settlementInvoiceList.get(0).get("SettlementStatus"),
                    "验证SettlementStatus");
            Logger.verifyEquals(2, (Integer) settlementInvoiceList.get(0).get("SettlementUser"), "验证SettlementUser");
            Logger.verifyEquals(null, (String) settlementInvoiceList.get(0).get("ProcessResult"), "验证ProcessResult");

            Logger.comment("校验Ymt_SettlementInvoice表 退款结算");
            Logger.verifyEquals(refundBillNo, (String) settlementInvoiceList.get(1).get("BusinessNo"),
                    "验证BusinessNo");
            Logger.verifyEquals(2, (Integer) settlementInvoiceList.get(1).get("BusinessType"),
                    "验证BusinessType");
            Logger.verifyEquals(orderId, (Integer) settlementInvoiceList.get(1).get("OrderId"),
                    "验证OrderId");
            Logger.verifyEquals(((BigDecimal) settlementInvoiceList.get(1).get("CashAmount"))
                    .add((BigDecimal) settlementInvoiceList.get(1)
                            .get("CouponAmount")), (BigDecimal) settlementInvoiceList.get(1)
                    .get("TotalAmount"),
                    "验证TotalAmount");
            Logger.verifyEquals(refundBill.getRefundAmount(),
                    (BigDecimal) settlementInvoiceList.get(1).get("CashAmount"),
                    "验证CashAmount");
            // 确认收货的ymt 平台优惠券
            Logger.verifyEquals(refundBill.getSettlementAmountOfCoupon(),
                    (BigDecimal) settlementInvoiceList.get(1).get("CouponAmount"),
                    "验证CouponAmount");
            Logger.verifyEquals(sellerId, (Integer) settlementInvoiceList.get(1).get("SellerId"),
                    "验证SellerId");
            Logger.verifyEquals("退款结算", (String) settlementInvoiceList.get(1).get("Remark"), "验证Remark");
            Logger.verifyEquals(2, (Integer) settlementInvoiceList.get(1).get("SettlementStatus"),
                    "验证SettlementStatus");
            Logger.verifyEquals(2, (Integer) settlementInvoiceList.get(1).get("SettlementUser"), "验证SettlementUser");
            Logger.verifyEquals("9002", (String) settlementInvoiceList.get(1).get("ProcessResult"), "验证ProcessResult");
            Logger.comment("校验ymt_orderinfo表");
            Logger.verifyEquals(10, (Integer) orderInfoList.get(0).get("iProductRefundStatus"),
                    "验证iProductRefundStatus");
            Logger.verifyEquals(1, (Integer) orderInfoList.get(1).get("iProductRefundStatus"),
                    "验证iProductRefundStatus");
            Logger.comment("校验ymt_orders表");
            Logger.verifyEquals(4, (Integer) ymtOrders.get(0).get("iTradingStatus"), "验证iTradingStatus");
            Logger.verifyEquals(1, (Integer) ymtOrders.get(0).get("iSalesRefundStatus"), "验证iSalesRefundStatus");
            Logger.comment("校验ymt_orderstate表");
            Logger.verifyEquals((BigDecimal) settlementInvoiceList.get(1).get("CashAmount"), (BigDecimal) ymtOrderState
                    .get(0).get("fRefundedAmountOfCash"), "验证fRefundedAmountOfCash");
            accountCallService.resetAccount(accountid, new BigDecimal(99999999), new BigDecimal(0));
        } catch (Exception e) {
            Logger.fail(e);
        }
    }
}
